package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.getIndependentAgentPicBean;
import com.ymatou.iapi.godmch.parameter.mchManageListBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.getIndependentAgentPicCall;
import com.ymatou.iapi.godmch.service.mchManageListCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
/**
*商户管理列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_mchManageList{
	private static mchManageListBean bean;
	private static mchManageListCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户管理列表");
	}

	@Before
	public void caseUp() {
		bean=new mchManageListBean();
		call=new mchManageListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_001() {
		Logger.start(true,"商户管理列表-0所有-返回成功");
		try {
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //供货商
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
            Thread.sleep(5000);
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createSupplierCodeCall.getCode());
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            //渠道商
            String inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);            
            
            bean.setMchId(mchId);
            bean.setShopType(0);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_002() {
		Logger.start(true,"商户管理列表-1供货商-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //供货商
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
            Thread.sleep(5000);
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createSupplierCodeCall.getCode());
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            bean.setMchId(mchId);
         //   bean.setShopType(1);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_003() {
		Logger.start(true,"商户管理列表-2渠道商-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //渠道商
            String inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);            
            
            bean.setMchId(mchId);
            bean.setShopType(2);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_004() {
		Logger.start(true,"商户管理列表-3分销代理-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchBean.setMchShareType(3);// 店铺买家端呈现形式//1：小程序 2：H5 3：独立小程序 4：独立h5 5：继承版小程序
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);         
            
            bean.setMchId(mchId);
            bean.setShopType(3);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_005() {
		Logger.start(true,"商户管理列表-4分销小店-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchBean.setMchShareType(3);// 店铺买家端呈现形式//1：小程序 2：H5 3：独立小程序 4：独立h5 5：继承版小程序
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);         
            
            bean.setMchId(mchId);
            bean.setShopType(4);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_007() {
		Logger.start(true,"商户管理列表-显示第中间页-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //供货商
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
            Thread.sleep(5000);
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createSupplierCodeCall.getCode());
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            //渠道商1
            String inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean); 
            //渠道商2
            inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);  
            
            bean.setMchId(mchId);
            bean.setShopType(0);
            bean.setPageIndex(2);
            bean.setPageSize(1);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals(3, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_mchManageList_008() {
		Logger.start(true,"商户管理列表-显示第最后页-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //供货商
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
            Thread.sleep(5000);
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createSupplierCodeCall.getCode());
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            //渠道商1
            String inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean); 
            //渠道商2
            inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);  
            
            bean.setMchId(mchId);
            bean.setShopType(0);
            bean.setPageIndex(3);
            bean.setPageSize(1);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals(3, call.getTotal(), "验证总数Total");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}